package modele;


import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class ConnectionManager {

	private static Connection connection = null;

	public static Connection getConnection() {
		if(connection == null) {
			try {
				 Statement st = null;
			        ResultSet rs = null;
				String url = "jdbc:mysql://localhost:3306/";
				String dbName = "proxirabais";
				String driver = "com.mysql.jdbc.Driver";
				String userName = "root"; 
				String password = "";

				Class.forName(driver).newInstance();
				connection = (Connection) DriverManager.getConnection(url+dbName,userName,password);
				st = (Statement) connection.createStatement();
	            rs = st.executeQuery("SELECT VERSION()");

	            if (rs.next()) {
	                System.out.println(rs.getString(1));
	            }

	            
				System.out.println("Connecte");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return connection;
	}
	public static void closeConnection() {
		try {
			if(connection != null) connection.close();
		} catch(SQLException e) {
			System.err.println(e.getMessage());
		}
	}
}
